#!./perl -w

# ------------------------------------------------------------

# checkmail.pl, by Jean-Pierre Girard (jpg@corrado.sun.com)
# This allows the user to edit or create the _info file
# necessary for the CDware.

# ------------------------------------------------------------

# Bugs and other fixes

# ------------------------------------------------------------

##############################################################################
# Main block
##############################################################################
$MAILFILENAME = $ENV{"HOME"} . "/.mailcap";
$TMPMAILFILENAME = "/tmp/.mailcap";
unless (-e $MAILFILENAME) {
	die "ERROR: $MAILFILENAME doesn't exist\n";
}

if (-s $MAILFILENAME && open (MAILFILE, $MAILFILENAME)) {
	if (open (TMPMAILFILE, "> $TMPMAILFILENAME")) {
		while (<MAILFILE>) {
			$Line = $_;
			if ($Line ne "application/x-spam-sh; /bin/sh %s \n") {
				print TMPMAILFILE $Line;
				#print "jpg\n";
			}
		}
		close(MAILFILE);
		close(TMPMAILFILE);
		#unlink($MAILFILENAME) || die "Can't delete $MAILFILENAME";
		#print "rename($TMPMAILFILENAME, $MAILFILENAME) || die \"Can't rename $TMPMAILFILENAME to $MAILFILENAME\"";
		rename("/tmp/.mailcap", "/home/jpg/.mailcap") || die "Can't rename $TMPMAILFILENAME to $MAILFILENAME";
		#rename($TMPMAILFILENAME, $MAILFILENAME) || die "Can't rename $TMPMAILFILENAME to $MAILFILENAME";
	}
} else {
	print "ERROR: couldn't open $MAILFILENAME\n";
}

################################################################################
# Define FORMATS (no more code)
################################################################################
